<template>
  <el-container class="home-container">
    <!--头部布局-->
    <el-header>
      <div>
        <img src="../../assets/logo.png" alt class="logo_img" />
        <span>我的工厂后台管理</span>
      </div>
      <div>欢迎回来  @ >< @  您的工厂ID: {{fac_id}}</div>
      <el-button type="info" @click="logout">安全退出</el-button>
    </el-header>
    <el-container>
      <!--侧边布局-->
      <el-aside :width="isCollapse ?'64px':'200px'">
        <!--伸缩按钮-->
        <div class="toggle-button" @click="toggleCollapase">|||</div>
        <!--侧边栏菜单区 unique-opened="true" 只保持一个菜单展开 router开启路由 active-text-color 颜色-->
        <el-menu background-color="#545c64" text-color="#fff" active-text-color="#409eff" unique-opened
                 :collapse-transition="true" :router="true">
          <el-submenu index="1">
            <template slot="title">
              <i :class="iconsObject[101]"></i>
              <span>我的工厂</span>
            </template>
            <el-menu-item index="/myEquip">
              <template slot="title" >
                <i :class="iconsObject[102]"></i>
                <span>我的设备</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/myOrder">
              <template slot="title" >
                <i :class="iconsObject[201]"></i>
                <span>我的订单</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!--主体布局-->
      <el-main>
        <!--路由占位符-->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      // 左侧菜单
      menuList: [],
      iconsObject: {
        '100':'iconfont iconguanliyuan',
        '200':'iconfont iconsport',
        '101':'iconfont icondenglu',
        '102':'iconfont iconmima',
        '103':'iconfont iconsport',
        '104':'iconfont iconshangpin',
        '201':'iconfont iconshu',
        '202':'iconfont iconkaluli',
        '203':'iconfont iconshiwu',
        '204':'iconfont icondenglu',
      },
      isCollapse:false,
      // 被激活的连接
      activePath:'',
      fac_id:'',
    }
  },
  // 类似onload
  created() {
    this.activePath = window.sessionStorage.getItem('activePath');// 取出session里的访问路径
    this.getTempFacId();//取出当前工厂的ID
  },
  methods: {
    getTempFacId(){
      this.fac_id = window.sessionStorage.getItem('fac_id');
    },
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    // 切换菜单折叠与展开
    toggleCollapase(){
      this.isCollapse = !this.isCollapse;
    },
    // 保存二级菜单的路径
    saveNavState(activePath){
      window.sessionStorage.setItem('activePath',activePath);// 存放点击的二级菜单
      this.activePath = activePath;// 给点击的菜单添加高亮
    },
  }
};
</script>
<style lang="less" scoped>
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;// 左右贴边
  padding-left: 0%;// 左边界
  align-items: center;// 水平
  color: #fff;
  font-size: 20px;
  > div { //左侧div加布局
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}
.el-aside {
  background-color: #333744;
  .el-menu{
    border-right: none;// 对其右边框
  }
}
.el-main {
  background-color: #eaedf1;
}
.home-container {
  height: 100%;
}
.logo_img {
  width: 10%;
  height: 100%;
}
.iconfont{
  margin-right: 10px;
}
.toggle-button{
  background-color:#4A5064;
  font-size: 10px;
  line-height: 24px;
  color:#fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;// 显示鼠标指针为：小手
}
</style>